/*
 * JStellaOptionsApplet.java
 *
 * Created on September 3, 2007, 11:06 PM
 */

package jstella.runner;

import javax.swing.SwingUtilities;

/**
 * This is intended to be a separate applet, used in conjunction with JStellaApplet,
 * that will allow the user to flip console switches separately of the main applet.
 * @author J.L. Allen
 */
public class JStellaOptionsApplet extends javax.swing.JApplet {
    private JStellaApplet myMainApplet=null;
    
    /** Initializes the applet JStellaOptionsApplet */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        PUDebug = new javax.swing.JPopupMenu();
        MITogglePause = new javax.swing.JMenuItem();
        PanelOptions = new javax.swing.JPanel();
        ButtonReset = new javax.swing.JButton();
        ButtonSelect = new javax.swing.JButton();
        ButtonHelp = new javax.swing.JButton();
        LabelPause = new javax.swing.JLabel();

        MITogglePause.setText("Toggle pause");
        MITogglePause.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MITogglePauseActionPerformed(evt);
            }
        });

        PUDebug.add(MITogglePause);

        PanelOptions.setFocusable(false);
        PanelOptions.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                PanelOptionsMousePressed(evt);
            }
        });
        PanelOptions.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                PanelOptionsMouseMoved(evt);
            }
        });

        ButtonReset.setText("Reset");
        ButtonReset.setDefaultCapable(false);
        ButtonReset.setFocusable(false);
        ButtonReset.setRequestFocusEnabled(false);
        ButtonReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonResetActionPerformed(evt);
            }
        });

        PanelOptions.add(ButtonReset);

        ButtonSelect.setText("Select");
        ButtonSelect.setDefaultCapable(false);
        ButtonSelect.setFocusable(false);
        ButtonSelect.setRequestFocusEnabled(false);
        ButtonSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonSelectActionPerformed(evt);
            }
        });

        PanelOptions.add(ButtonSelect);

        ButtonHelp.setText("Help");
        ButtonHelp.setDefaultCapable(false);
        ButtonHelp.setFocusable(false);
        ButtonHelp.setRequestFocusEnabled(false);
        ButtonHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonHelpActionPerformed(evt);
            }
        });

        PanelOptions.add(ButtonHelp);

        PanelOptions.add(LabelPause);

        getContentPane().add(PanelOptions, java.awt.BorderLayout.CENTER);

    }// </editor-fold>//GEN-END:initComponents

    private void PanelOptionsMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PanelOptionsMousePressed
       if (SwingUtilities.isMiddleMouseButton(evt)==true)
       {
           PUDebug.show(PanelOptions, evt.getX(), evt.getY());
       }
    }//GEN-LAST:event_PanelOptionsMousePressed

    private void PanelOptionsMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PanelOptionsMouseMoved
// TODO add your handling code here:
    }//GEN-LAST:event_PanelOptionsMouseMoved

    private void MITogglePauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MITogglePauseActionPerformed
 if (getMainApplet()!=null)
           {
               getMainApplet().toggleManualPause();
           }//end : found main applet
    }//GEN-LAST:event_MITogglePauseActionPerformed

    private void ButtonHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonHelpActionPerformed
           if (getMainApplet()!=null)
           {
               getMainApplet().doHelp();
           }//end : found main applet
    }//GEN-LAST:event_ButtonHelpActionPerformed

    private void ButtonSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonSelectActionPerformed
       if (getMainApplet()!=null)
           {
               getMainApplet().doSelect();
           }//end : found main applet
    }//GEN-LAST:event_ButtonSelectActionPerformed

    private void ButtonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonResetActionPerformed
 if (getMainApplet()!=null)
           {
               getMainApplet().doReset();
           }//end : found main applet
    }//GEN-LAST:event_ButtonResetActionPerformed
    
    private JStellaApplet getMainApplet()
    {
        if (myMainApplet==null)
        {
       
        java.util.Enumeration zApplets=this.getAppletContext().getApplets();
        for (; zApplets.hasMoreElements() ;) {
            
            Object zObj=zApplets.nextElement();
            if (zObj instanceof JStellaApplet)
            {
                myMainApplet=(JStellaApplet)zObj;
                break;
            }//end : found a JStellaApplet
        }//end : for enumeration loop
              
        }//end : main applet not yet found
      
        return myMainApplet;
        
        
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonHelp;
    private javax.swing.JButton ButtonReset;
    private javax.swing.JButton ButtonSelect;
    private javax.swing.JLabel LabelPause;
    private javax.swing.JMenuItem MITogglePause;
    private javax.swing.JPopupMenu PUDebug;
    private javax.swing.JPanel PanelOptions;
    // End of variables declaration//GEN-END:variables
    
    //Good settings 240 x 35
}
